/**
 *Class DeleteWordScreen 
 *
 * version 1.0
 *
 * @author Jin Kit Chua
 * @version 20130319 V1.0
 */
package ch.zbw.iCoach.kit;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ch.zbw.iCoach.remo.MainLogic;

public class DeleteWordScreen {

	private Languages la;
	private MainLogic ml;

	private JFrame mainFrame;

	private JButton delete;
	private JButton cancel;

	private JTextField word1;

	private JPanel buttonPanel;
	private JPanel infoPanel;
	private JLabel msg;

	/**
	 * 
	 * @param ml reference of the mainlogic to use the interfacemethods
	 * @param la reference for translation
	 */
	public DeleteWordScreen(MainLogic ml, Languages la) {
		this.ml = ml;
		this.la = la;

		this.mainFrame = new JFrame();

		this.delete = new JButton();
		this.cancel = new JButton();

		this.buttonPanel = new JPanel();
		this.infoPanel = new JPanel();

		this.word1 = new JTextField();
		this.msg = new JLabel();
		paint();
	}

	public void paint() {
		this.mainFrame.setBackground(Color.lightGray);
		this.mainFrame.setResizable(false);

		String tempLang = this.la.switchLangDeleteWord();
		String[] parts = tempLang.split(",");
		String msg = parts[0];
		String buttonDelete = parts[1];
		String buttonCancel = parts[2];
		String title = parts[3];

		this.msg.setText(msg);
		this.delete.setText(buttonDelete);
		this.cancel.setText(buttonCancel);
		this.mainFrame.setTitle(title);

		this.mainFrame.setLayout(new BorderLayout(10, 20));
		this.infoPanel.setLayout(new GridLayout(2, 1, 20, 20));
		this.buttonPanel.setLayout(new GridLayout(1, 4, 20, 20));

		this.buttonPanel.add(this.delete);
		this.buttonPanel.add(this.cancel);

		this.infoPanel.add(this.msg);
		this.infoPanel.add(this.word1);

		this.mainFrame.add(this.buttonPanel, BorderLayout.SOUTH);
		this.mainFrame.add(this.infoPanel, BorderLayout.CENTER);

		this.mainFrame.setSize(400, 250);
		this.mainFrame.setVisible(true);
		this.mainFrame.setLocation(650, 400);

		this.delete.addActionListener(new ActionListenerOk());
		this.cancel.addActionListener(new ActionListenerCancel());
	}

	class ActionListenerCancel implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			mainFrame.dispose();
		}
	}

	class ActionListenerOk implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			ml.deleteWord(word1.getText());
			mainFrame.dispose();
		}
	}
}
